package com.yanghui.dtracing.plugin.thread;

import com.yanghui.dtracing.core.EnhancedInstance;
import com.yanghui.dtracing.core.opentracing.ScopeContext;
import com.yanghui.dtracing.core.opentracing.Tracing;
import com.yanghui.dtracing.core.plugin.interceptor.IConstructorInterceptor;
import com.yanghui.dtracing.core.utils.AsynAcross;
import io.opentracing.Span;

import java.util.concurrent.atomic.AtomicInteger;

public class ThreadConstructorInter implements IConstructorInterceptor {

    @Override
    public void onConstructor(EnhancedInstance thisObj, Object[] allArguments) throws Throwable {
        Span span = Tracing.getTracer().activeSpan();
        AtomicInteger atomicInteger = ScopeContext.getIncrement();
        thisObj.setDynamicField(new AsynAcross(span,atomicInteger));
    }
}
